<?php

/*
 * Created on 08.01.2007
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 * 
 * <example:bodyProcess></example:bodyProcess>
 */

m2import('phpinchains/psp/MethodTag.php');

class cms_tracingmenuHandler extends phpinchains_psp_MethodTag {

    /**
     * Is a body tag (if false, body is ignored)
     */
    var $tagType = PSP_BODY_TAG;
    /**
     * Tag name in form namespace:tagname
     */
    var $tagName = 'cms:tracingmenu';
    public $requiredAttributes = array(
    );
    public $attributes = array(
    );
    private $params = array();
    private $dba;

    function addParam($name, $value) {
        $this->params[$name] = $value;
    }

    function doStartTag() {
        // initializes $this->buffer and pushes the listener on the stack of the 
        // main output writer
        return PSP_EVAL_BODY_BUFFERED;
    }

    function doEndTag() {
        // separator=' &gt; '&linkclass='classname'&posopen='&lt;b&gt;'&posclose='&lt;/b&gt;'
        $params = $this->params;

        $ctx = base_ApplicationContext::getInstance();
        $udba = $ctx->getAccessFactory()->getConnection();
        $dctx = $ctx->getDocumentContext();
        $docs = $dctx->getDocTree();
        $ldba = $ctx->getAccessFactory()->getInstanceOf(base_AccessFactory::$CMSLang);
        $check = $ldba->getLanguages($this->langtable, true);
        $this->dba = $ctx->getAccessFactory()->getInstanceOf(base_AccessFactory::$CMS, $this->langtable);
        $this->doc_id = $dctx->getDocId();
        $buildMode = $dctx->getBuildMode();
        $env = $ctx->getEnvWrapper();
        $site_id = $dctx->getSiteId();
        $cfgPaths = $ctx->cfgPaths();

        $lang_name = $dctx->getLanguage('name');
        $lang_id = $dctx->getLanguage('id');
        $paramEnv = $dctx->getDoc()->getElements()->getByName('env');
        $paramEnv = $paramEnv[0]['data'];

        if (!isset($params['separator']))
            $params['separator'] = '';
        if (!isset($params['linkclass']))
            $params['linkclass'] = '';
        if (!isset($params['posopen']))
            $params['posopen'] = '';
        if (!isset($params['posclose']))
            $params['posclose'] = '';
        $output = '';
        $pathArray = $docs->extractPathArray($this->doc_id, 'id', true);
        if (($buildMode == base_templateEngine_BuildModes::$EXPORT)
                || ($buildMode == base_templateEngine_BuildModes::$PRINT)
                || ($buildMode == base_templateEngine_BuildModes::$CACHE)) {
            $home_id = $this->dba->getSitePubHomeId($site_id);
        } else {
            $home_id = $this->dba->getSiteHomeId($site_id);
        }
        if ($pathArray[0] != $home_id)
            array_unshift($pathArray, $home_id);
        $count = count($pathArray);
        for ($i = 0; $i < $count; $i++) {
            $doc = $docs->getById($pathArray[$i]);
            if ($doc['type'] == 'folder')
                continue;
            if ($pathArray[$i] == $this->doc_id) {
                $current = $docs->getByID($pathArray[$i]);
                $output .= $params['posopen'];
                $output .= ( $current['descr']) ? $current['descr'] : $current['name'];
                $output .= $params['posclose'];
                $output .= ( $i < ($count - 1)) ? $params['separator'] : '';
            } else {
                $current = $docs->getByID($pathArray[$i]);
                $output .= '<a href="' . base_templateEngine_TemplateEngineLinkBuilder::buildPageLink($buildMode, $current['id']) . '"';
                $output .= ( !empty($params['linkclass'])) ? ' class="' . $params['linkclass'] . '"' : '';
                $output .= '>';
                $output .= ( !empty($current['descr'])) ? $current['descr'] : $current['name'];
                $output .= '</a>';
                $output .= ( $i < ($count - 1)) ? $params['separator'] : '';
            }
            $this->related_docs[] = $pathArray[$i];
        }
        $this->registerRelatedDocuments($dctx);
        $this->out->write($output);
        return PSP_SKIP_BODY;
    }

}

?>